function select(curObj) {
	Map.applyBGColor(curObj["id"], "#ff0000", "0.4");
}
	        
function selectItem(id) {
	if (id == "") {
		alert("对象id不能为空！");
	} else if (Map.getItem(id) == null) {
		alert("对象不存在！");
	} else {
		if(Map.getSelection() != null){
			Map.clearBackground(Map.getSelection().id);
	        Map.clearSelection();
	     }
		Map.selectItem(id);
	}
}

function getSelected(id){
	if(Map.getSelection() != null){
		Map.clearBackground(Map.getSelection().id);
	    Map.clearSelection();
	}
	Map.selectItem(id);
}
function draw_route(id){
      if(id==1)
      {
          Map.clearDrawing();
          Map.drawLine(150,70,304,92,"#0000ff");
          Map.drawLine(304,92,240,174,"#0000ff");
          Map.drawLine(240,174,400,255,"#0000ff");
          Map.drawLine(400,255,285,302,"#0000ff");
          Map.drawLine(285,302,58,301,"#0000ff");
          Map.drawLine(58,301,106,380,"#0000ff");
          Map.drawLine(106,380,110,347,"#0000ff");
      }
      else if(id==2)
      {
      	  Map.clearDrawing();
          Map.drawLine(150,70,58,301,"#0000ff");
          Map.drawLine(58,301,113,320,"#0000ff");
          Map.drawLine(113,320,110,347,"#0000ff");
          Map.drawLine(110,347,106,380,"#0000ff");
          Map.drawLine(106,380,475,279,"#0000ff");      
      }
      else if(id==3)
      {
          Map.clearDrawing();
          Map.drawLine(177,221,240,174,"#0000ff");
          Map.drawLine(240,174,304,92,"#0000ff");
          Map.drawLine(304,92,400,255,"#0000ff");
          Map.drawLine(400,255,285,302,"#0000ff"); 
          Map.drawLine(285,302,110,347,"#0000ff");
          Map.drawLine(110,347,58,301,"#0000ff");         
      }       
}

var scenes = {
	quanjing:"http://cpc.sjtu.edu.cn/map/maps/quanjing.swf",
	baiyangdian:"http://cpc.sjtu.edu.cn/map/maps/baiyangdian.swf",
	hehua:"http://cpc.sjtu.edu.cn/map/maps/hehua.swf",
	yiguo:"http://cpc.sjtu.edu.cn/map/maps/yiguo.swf"};

var placeHtml = {
	def:"您现在的位置是：<a href='javascript:void(0);'>首页</a>",
	jingqu:{
		def:"><a href=\"javascript:loadScene('quanjing','jingqu');\">白洋淀景区</a>",
		baiyangdian:"><a href=\"javascript:loadScene('baiyangdian','jingqu','baiyangdian')\">白洋淀文化苑</a>",
		hehua:"><a href=\"javascript:loadScene('hehua','jingqu','hehua');\">荷花大观园</a>",
		yiguo:"><a href=\"javascript:loadScene('yiguo','jingqu','yiguo');\">异国风情园</a>"
	},
	minsu:{
		def:"><a href=\"javascript:loadScene('quanjing','minsu');\">民俗活动</a>"
	},
	lvyou:{
		def:"><a href=\"javascript:loadScene('quanjing','lvyou');\">旅游路线</a>"
	}
};

//loadScene()默认只有一个参数scene,代表的是MapDiv里load的场景id
//还有两个参数，是属于多态的，需要的时候才添加
//参数一是指应用
//参数二是指应用中的子选项
//例：您现在的位置是：首页>白洋淀景区>荷花大观园
//参数一决定了白洋淀景区,参数二决定了荷花大观园
function loadScene(scene) {
	var html = placeHtml.def;
	
	if(arguments[1]){
		var app = arguments[1];
		html += placeHtml[app].def;
		
		if(arguments[2]){
			var id = arguments[2];
			html += placeHtml[app][id];
		}
	}
	
	$("#place").html(html);
	Map.loadScene("", "", "", "", scenes[scene]);
}

function loadSorry(){
   	alert("There is no map here!");
}
/**
活动地点*/
var ids = new Array();

function clearAllBGColor() {
	var id;
	while(ids.length > 0){
		id = ids.pop();
		Map.clearBackground(id);
	}
}
        
function activityPlace(id){
	clearAllBGColor();
	     
	switch(id){
	case 1:
		Map.selectItem(2);
		Map.selectItem(8);
		ids.push(2);
		ids.push(8);
		break;
	case 2:
		Map.selectItem(2);
		Map.selectItem(8);
		Map.selectItem(9);
		ids.push(2);
		ids.push(8);
		ids.push(9);
		break;
	case 0:
		Map.selectItem(9);
		ids.push(9);
		break;
	}
}

function RefreshPanel(num){
	$.post("RefreshPanel",{panel:num},function(data){		
		$("#subPanel").animate({
			width: 'hide',
			opactiy: 'hide'
		}, 'normal').html(data).animate({
			width: 'show',
			opactiy: 'show'
		}, 'normal');
		
		addToggleToNav();					
	});
}

var gotoId = 0;
function goToItem(id){

	if(Map.getSelection() != null){
		Map.clearBackground(Map.getSelection().id);
	    Map.clearSelection();
	}
	
	if(Map.getItem(id) == null){
		gotoId = id;
		
		if(id<=68&&id>=58){
			Map.loadScene("", "", "", "", "http://cpc.sjtu.edu.cn/map/maps/yiguo.swf");
		}else if(id>=10&&id<=38){
			Map.loadScene("", "", "", "", "http://cpc.sjtu.edu.cn/map/maps/hehua.swf");
		}else if(id>=1&&id<=9){
			Map.loadScene("", "", "", "", "http://cpc.sjtu.edu.cn/map/maps/quanjing.swf");
		}else{
			Map.loadScene("", "", "", "", "http://cpc.sjtu.edu.cn/map/maps/baiyangdian.swf");
		}
	}else
		Map.selectItem(id);
	
	
}

function load(){
	if(gotoId > 0)
		Map.selectItem(gotoId);
}


//开始搜索
function SearchPorts(type){	
	$("#contentList:visible").animate({
			width: 'hide',
			opacity:'hide'
		},'normal');
	$("#resultTitle").find("div").html("搜索结果");
	$.post("search",{query:encodeURI($("#searchText").val()),type:encodeURI(type)},function(data){
		$("#answer").html(data).animate({
			width: 'show',
			opacity:'show'
		},'normal');	
	});
}

//上传附加应用
function updateExtend(){
	$("#extendForm:visible").animate({
			width: 'hide',
			opacity:'hide'
		},'normal');
	$.post("UpdateExtend",{appName:encodeURI($("#extendAppName").val()),
		appURL:encodeURI($("#extendAppURL").val())},function(data){
			$("#answer").html(data).animate({
				width: 'show',
				opacity: 'show'
			}, 'normal')
	})	
}
		    
var outPort = true;
var outMov = true;
function mouseover(curObj) {
	var iTop = mapDiv.offsetTop + curObj["y"];
    var iLeft = mapDiv.offsetLeft + curObj["x"];
        		
    moveDiv.style.top = iTop-15;
    moveDiv.style.left = iLeft-15;
	outPort = false;

    $.post("Detail",{panel:curObj["id"]},function(data){
		$("#moveDiv").mouseover(function(){
			outMov = false;
		});
		
		$("#moveDiv").mouseout(function(){
			outMov = true;	
			if(outPort && outMov){
				$(this).css("display","none");
			}
		});
		
		$("#moveDiv").html(data).animate({
			width: 'show',
			opactiy: 'show'
		}, 'normal');
	});
}
function mouseout(curObj){
	outPort = true;
	if(outPort && outMov){
		$("#moveDiv").css("display","none");
	}
	
}
var apply = 100;
function mov_enter(num){
	$("#moveDiv").css("display","none");
	
	apply = 100;
	switch(num){
		case 5:
			loadScene("yiguo","jingqu","yiguo");
			RefreshPanel(13);
			break;
		case 7:
			loadScene("baiyangdian","jingqu","baiyangdian");
			RefreshPanel(11);
			break;
		case 8:
			loadScene("hehua","jingqu","hehua");
			RefreshPanel(12);
			break;
		case 20:
			RefreshPanel(20);
			break;
		case 30:
			RefreshPanel(0);
			break;
		default:
			loadSorry();
			break;
	}
}

function loadApp(applyId){
	if(apply != applyId){
		apply = applyId;
					
		var app;
		switch(apply){
		case 1:
			app = "jingqu"; break;
		case 2:
			app = "minsu"; break;
		case 3:
			app = "lvyou"; break;
		default:
			app = null; break;
		}
		
		loadScene("quanjing",app);
		RefreshPanel(apply);
	}
}